package com.cxcy.swustlearner.controller;

import com.cxcy.swustlearner.pojo.StaticUser;
import com.cxcy.swustlearner.pojo.TaskStatus;
import com.cxcy.swustlearner.service.TaskStatusService;
import common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tasks/status")
public class TaskStatusController {
    @Autowired
    private TaskStatusService taskStatusService;
    @PutMapping()
    public Result updateTaskStatus(@RequestBody TaskStatus taskStatus) {
        taskStatus.setUid(StaticUser.uid);
        taskStatusService.updateTaskStatus(taskStatus);
        return Result.success("状态更新成功");
    }

    /**
     * 目前只返回了完成或未完成的用户，还未进行统计
     * @param taskId
     * @param status
     * @return
     */
    @GetMapping()
    public Result getTaskStatus(String taskId, @RequestParam(defaultValue = "0") int status) {
        return Result.success(taskStatusService.getAllTaskStatus(taskId, status));
    }
}